// pages/movie/movie.js
const {handleTitle,transfromStar} = require("../../utils/index.js")
const {http1,http2} = require("../../models/movie1")
Page({
  /**
   * 页面的初始数据
   */
  data: {
    movies:[],
    swiperParams:{
      defaultColor:"#fff",
      dots:true,
      autoplay:true,
      circular:true,
      activeColor:"#ff2d51"
    },
    banners:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
/*   onLoad: function (options) {
    wx.request({
      url: 'http://192.168.4.18:8000/',
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result)=>{
        // console.log(result.data.result);
        // this.setData({
        //   movies:result.data.result
        // })
        this.handleHttpData(result.data.result)
      }
    });
  }, */
  onLoad: function () {
    /* wx.request({
      url: 'http://192.168.4.18:8000/',
      header: {'content-type':'application/json'},
      method: 'GET',
      dataType: 'json',
      responseType: 'text',
      success: (result)=>{
        this.handleHttpData(result.data.result)
      }
    });

    wx.request({
      url: 'http://192.168.4.18:8000/banner',
      method: 'GET',
      success: (res)=>{
        this.setData({
          banners:res.data
        })
      }
    }); */
    http1({
      success:res=>{
        this.handleHttpData(res.data.result)
      }
    }),
    http2({
      success:res=>{
        this.setData({
          banners:res.data
        })
      }
    })

  },

  handleHttpData(res){
        // console.log(res);
        res.forEach(item=>{
          // console.log(item);
          // item["title"]= this.handTitle(item["title"])
          item["title"]= handleTitle(item["title"])
          item["raiting"]= transfromStar(item["raiting"])
        })
        console.log(res);
        this.setData({
          movies:res
        })
  },
})